<template>
	<div class="pages">
		<el-form :inline="true" size="small" :model="dataForm" label-width="80px">
			<el-form-item>
				<el-button type="primary" @click="addOrUpdateHandle()" v-if="$hasPermission('api/authgroup/add')">添加</el-button>
			</el-form-item>
			<el-form-item label="角色名称:">
				<el-input v-model="dataForm.keyword" placeholder="请输入" clearable></el-input>
			</el-form-item>
			<el-form-item label="状态:">
				<el-select v-model="dataForm.status" placeholder="请选择" clearable>
					<el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="getDataList">搜索</el-button>
			</el-form-item>
		</el-form>
		<el-table :data="dataList" v-loading="dataListLoading" border style="width: 100%" header-align="center">
			<el-table-column prop="title" align="center" label="角色名称">
			</el-table-column>
			<el-table-column prop="total" align="center" label="管理员数量">
			</el-table-column>
			<el-table-column prop="mobile" align="center" label="状态">
				<template slot-scope="scope">
					<el-tag type="success" v-if="scope.row.status==1">启用</el-tag>
					<el-tag type="danger" v-if="scope.row.status==0">禁用</el-tag>
				</template>
			</el-table-column>
			<el-table-column align="center" label="操作" width="160">
				<template slot-scope="scope">
					<el-button type="text" @click="addOrUpdateHandle(scope.row)" v-if="$hasPermission('api/authgroup/edit')">编辑</el-button>
					<el-button type="text" @click="deleteHandle(scope.row.id)" v-if="$hasPermission('api/authgroup/delete')">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
			layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
			@current-change="pageCurrentChangeHandle">
		</el-pagination>
		<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
	</div>
</template>

<script>
	import mixinViewModule from '@/mixins/view-module'
	import AddOrUpdate from './addAuth.vue'
	export default {
		mixins: [mixinViewModule],
		data() {
			return {
				mixinViewModuleOptions: {
					getDataListURL: '/api/authgroup/getlist',
					getDataListIsPage: true,
					deleteURL: '/api/authgroup/delete',
					deleteIsBatch: true,
					createdIsNeed: true,
				},
				dataForm: {
					keyword: '',
					status: '',
				},
				statusList: [{
					value: 1,
					label: '启用'
				}, {
					value: 0,
					label: '禁用'
				}]
			}
		},
		components: {
			AddOrUpdate
		},
		methods: {
			addOrUpdateHandle(row) {
				if (row) {
					console.log(row)
					this.addOrUpdateVisible = true
					this.$nextTick(() => {
						console.log(row)
						this.$refs.addOrUpdate.dataForm.id = row.id
						this.$refs.addOrUpdate.dataForm.ids = row.rules
						this.$refs.addOrUpdate.dataForm.title = row.title
						this.$refs.addOrUpdate.dataForm.status = String(row.status)
						this.$refs.addOrUpdate.init()
					})
				} else {
					this.addOrUpdateVisible = true
					this.$nextTick(() => {
						this.$refs.addOrUpdate.init()
					})
				}

			}
		},
		created() {}
	}
</script>
<style lang="scss" scoped>
	.pages{
		padding: 0;
	}
</style>